package com.sunnada.exam.service;

import com.sunnada.exam.dao.ResultsMapper;
import com.sunnada.exam.po.ResultsPo;
import com.sunnada.exam.vo.ResultsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("resultsService")
public class ResultsService {

    @Autowired
    ResultsMapper resultsMapper;

    public List<ResultsVo> listPage(){
        List<ResultsVo> result = new ArrayList<>();
        List<ResultsPo> list = resultsMapper.list();
        for (ResultsPo resultsPo : list) {
            result.add(new ResultsVo(resultsPo));
        }
        return result;
    }

    public List<ResultsPo> list(){
        return resultsMapper.list();
    }

    public ResultsVo one(String id){
        return new ResultsVo(resultsMapper.one(id));
    }

    public boolean insert(String name,String result,int tid){
        System.out.println(result);
        return insert(new ResultsPo(name,result,tid));
    }

    public boolean insert(ResultsPo resultsPo){
        return resultsMapper.insert(resultsPo);
    }

    public boolean delete(String id){
        return resultsMapper.delete(id);
    }
}
